/**
 * ajax请求配置
 */
import axios from "axios";
import router from "@/router";


// axios默认配置
// eslint-disable-next-line no-unused-vars
const requests = axios.create({
    baseURL:"http://localhost:8081",
    timeout:6000,
});

requests.interceptors.request.use((config)=>{
    config.headers['Content-Type'] = 'application/json;charset=utf-8';
    let json = sessionStorage.getItem("username")
    if(!json){
        router.push("/login")
    }
    return config;
},error => {
    return Promise.reject(error)
});

requests.interceptors.response.use((res)=>{
    return res.data;
// eslint-disable-next-line no-unused-vars
},(error)=>{
    return Promise.reject(new Error('faile'));
});

export const addTeacher =(data) => requests({url:'/Teacher/insertTeacher',method:'post',params:data});

export const getKecheng =() => requests({url:'/course/getCourses',method:'get'});

export const getXuesheng = () => requests({url:'/Student/numberOfStudents',method:'get'});

export const getLaoshi = () => requests({url:'/Teacher/numberOfTeachers',method:'get'});

export const deleteStudent = (sid) => requests({url:`/Student/deleteStudentBySid/${sid}`,method:'delete'});

export const addStudent = (data) => requests({url:'/Student/insertStudent',method:'post',params:data});

export const deleteById = (cid) => requests({url:`/banji/deleteById/${cid}`,method:'post'});

export const getBanji = () =>requests({url:'/banji/getBanjis/',method:'get'});

export const insertBanji = (banji) =>requests({url:'/banji/insertBanji/',method:'post',params:banji });

export const getLibraryList = () =>requests({url:'/library/all',method:'get'});

export const insertLibrary = (data) => requests({url:'/library/insert',method:'post',params:data});

export const getLibrary = (id) => requests({url:`/library/findLib/${id}`,method:'get'});

export const insertQuestion = (question) => requests({url:'/question/insert',method:'post',params:question});

export const findQuestionList = (lid) => requests({url:`/library/find/${lid}`,method:'get'});

export const deleteLibrary = (id) => requests({url:`/library/delete/${id}`,method:'post'});

export const newPaperAuto = (paperId)=> requests({url:`/paper/newAuto/${paperId}`,method:'get'});

export const newPaperHand = (datas) => requests({url:'/paper/new',method:'post',params:datas});

export const getPaperList = () => requests({url:'/paper/list',method:'get'});

export const getPaperDeatils = (paperId) => requests({url:`/paper/details/${paperId}`,method:'get'});

export const findQuestionDetails = (qid) => requests({url:`/question/findById/${qid}`,method:'get'});

export const deleteQuestion = (qid) => requests({url:`/question/delete/${qid}`,method:'post'});

export const insertAuto =(file) => requests({url:'/question/autoInsert',method:'post',params:file})

export default requests;
